package edu.ptu.shortlink.admin.common.convention.exception;

import edu.ptu.shortlink.admin.common.convention.errorcode.BaseErrorCode;
import edu.ptu.shortlink.admin.common.convention.errorcode.IErrorCode;

import java.util.Optional;

/**
 * @BelongsProject: shortlink
 * @BelongsPackage: edu.ptu.shortlink.admin.common.convention.exception
 * @Author: HYJ
 * @CreateTime: 2025-04-23  17:49
 * @Description: 服务端异常
 * @Version: 1.0
 */
public class ServiceException extends AbstractException {


    public ServiceException(String message) {
        this(message, null, BaseErrorCode.SERVICE_ERROR);
    }


    public ServiceException(IErrorCode errorCode) {
        this(null, errorCode);
    }


    public ServiceException(String message, IErrorCode errorCode) {
        this(message, null, errorCode);
    }


    public ServiceException(String message, Throwable throwable, IErrorCode errorCode) {
        super(Optional.ofNullable(message).orElse(errorCode.message()),
                throwable, errorCode);
    }

    @Override
    public String toString() {
        return "ServiceException{" +
                "errorCode='" + errorCode + '\'' +
                ", errorMessage='" + errorMessage + '\'' +
                '}';
    }
}
